/*
 * Copyright 2010 Aekold Helbrass
 * 
 * This file is part of RosterComposer.
 * 
 * RosterComposer is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * RosterComposer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with RosterComposer.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.heresylabs.rostercomposer.units;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aekold Helbrass <Helbrass@gmail.com>
 */
public class Option extends BaseEntry {

    @XmlAttribute(name = "any")
    private boolean any;
    @XmlAttribute(name = "requireNumber")
    private int requireNumber;
    @XmlAttribute(name = "require")
    private String require;
    @XmlAttribute(name = "conflict")
    private String conflict;
    @XmlAttribute(name = "anyModels")
    private boolean anyModels;
    @XmlAttribute(name = "repeatable")
    private boolean repeatable;
    @XmlAttribute(name = "forEach")
    private boolean forEach;
    transient private String externalForm;

    public boolean isLeaf() {
        return options == null || options.isEmpty();
    }

    public boolean isFree() {
        return cost < 1;
    }

    @XmlTransient
    public boolean isAny() {
        return any;
    }

    public boolean isOne() {
        return !any;
    }

    @XmlTransient
    public boolean isRepeatable() {
        return repeatable;
    }

    @XmlTransient
    public boolean isAnyModels() {
        return anyModels;
    }

    @XmlTransient
    public boolean isForEach() {
        return forEach;
    }

    @XmlTransient
    public String getRequire() {
        return require;
    }

    @XmlTransient
    public String getConflict() {
        return conflict;
    }

    @XmlTransient
    public int getRequireNumber() {
        return requireNumber;
    }

    @Override
    public String toString() {
        if (externalForm == null) {
            /*
             * if it's leaf - print with price (or free) label
             * if it's not leaf and free - name only
             * if it's not leaf and not free - print with price
             */

            if (!isLeaf() && isFree()) {
                externalForm = name;
            }
            else {
                externalForm = "<html>" + name + " <small>for</small> " + (cost < 1 ? "free" : (cost + " <small>pts</small>"));
            }
        }
        return externalForm;
    }

    // <editor-fold defaultstate="collapsed" desc=" for serializer only ">
    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setAny(boolean any) {
        this.any = any;
    }

    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setAnyModels(boolean anyModels) {
        this.anyModels = anyModels;
    }

    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setConflict(String conflict) {
        this.conflict = conflict;
    }

    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setExternalForm(String externalForm) {
        this.externalForm = externalForm;
    }

    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setForEach(boolean forEach) {
        this.forEach = forEach;
    }

    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setRepeatable(boolean repeatable) {
        this.repeatable = repeatable;
    }

    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setRequire(String require) {
        this.require = require;
    }

    /**
     * @deprecated this method is for serializer only
     */
    @Deprecated
    public void setRequireNumber(int requireNumber) {
        this.requireNumber = requireNumber;
    }
    // </editor-fold>

}
